<template>
  <div class="container">
    <div class="title">
      <span>修改仓库</span> <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
    </div>
    <el-divider></el-divider>
    <div class="wrap">
      <el-row>
        <el-col :lg="16" :md="20" :sm="24" :xs="24">
          <el-form :model="form" status-icon ref="form" label-width="100px" v-loading="loading" @submit.native.prevent>
            <el-form-item label="仓库编码" prop="code">
              <el-input size="medium" v-model="form.code" placeholder="请填写仓库编码"></el-input>
            </el-form-item>
            <el-form-item label="仓库名称" prop="name">
              <el-input size="medium" v-model="form.name" placeholder="请填写仓库名称"></el-input>
            </el-form-item>
            <el-form-item label="面积" prop="size">
              <el-input size="medium" v-model="form.size" placeholder="请填写面积"></el-input>
            </el-form-item>
            <el-form-item label="手机号" prop="phone">
              <el-input size="medium" v-model="form.phone" placeholder="请填写手机号"></el-input>
            </el-form-item>
            <el-form-item label="公司名字" prop="company">
              <el-input size="medium" v-model="form.company" placeholder="请填写公司名字"></el-input>
            </el-form-item>
            <el-form-item label="联系人" prop="contactor">
              <el-input size="medium" v-model="form.contactor" placeholder="请填写联系人"></el-input>
            </el-form-item>
            <el-form-item label="邮编" prop="postcode">
              <el-input size="medium" v-model="form.postcode" placeholder="请填写邮编"></el-input>
            </el-form-item>
            <div class="box">
              <el-form-item label="类型" prop="type">
                <el-select v-model="form.type" filterable placeholder="请选择">
                  <el-option v-for="item in type" :key="item.id" :label="item.name" :value="item.id"> </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="状态" prop="status">
                <el-select v-model="form.status" filterable placeholder="请选择">
                  <el-option v-for="item in status" :key="item.id" :label="item.name" :value="item.id"> </el-option>
                </el-select>
              </el-form-item>
            </div>
            <el-form-item label="地域" prop="regionals">
              <el-input size="medium" v-model="form.regionals" placeholder="请填写地域"></el-input>
            </el-form-item>
            <el-form-item label="国家" prop="country">
              <el-input size="medium" v-model="form.country" placeholder="请填写国家"></el-input>
            </el-form-item>
            <el-form-item label="州/省" prop="province">
              <el-input size="medium" v-model="form.province" placeholder="请填写州/省"></el-input>
            </el-form-item>
            <el-form-item label="市/区县" prop="city">
              <el-input size="medium" v-model="form.city" placeholder="请填写市/区县"></el-input>
            </el-form-item>
            <el-form-item label="街道" prop="street">
              <el-input size="medium" v-model="form.street" placeholder="请填写街道"></el-input>
            </el-form-item>
            <el-form-item label="单位/公寓/套房编号" prop="apartment">
              <el-input size="medium" v-model="form.apartment" placeholder="请填写单位/公寓/套房编号"></el-input>
            </el-form-item>
            <el-form-item label="描述" prop="description">
              <el-input
                size="medium"
                type="textarea"
                :autosize="{ minRows: 4, maxRows: 8 }"
                placeholder="请输入描述"
                v-model="form.description"
              >
              </el-input>
            </el-form-item>
            <el-form-item label="时区" prop="timeZone">
              <el-input size="medium" v-model="form.timeZone" placeholder="请填写时区"></el-input>
            </el-form-item>
            <el-form-item class="submit">
              <el-button type="primary" @click="submitForm('form')">保 存</el-button>
              <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import warehouse from '@/model/warehouse'

export default {
  props: {
    editWarehouseID: {
      type: String,
    },
  },
  data() {
    return {
      loading: false,
      form: {
        code: '',
        name: '',
        size: '',
        phone: '',
        description: '',
        province: '',
        city: '',
        contactor: '',
        postcode: '',
        type: false,
        status: true,
        street: '',
        apartment: '',
        timeZone: '',
        country: '',
        province: '',
        city: '',
      },
      type: [
        {
          id: false,
          name: '标准',
        },
        {
          id: true,
          name: '中转',
        },
      ],
      status: [
        {
          id: false,
          name: '不可用',
        },
        {
          id: true,
          name: '可用',
        },
      ],
    }
  },
  async mounted() {
    this.loading = true
    this.form = await warehouse.queryWarehouse(this.editWarehouseID)
    this.loading = false
    console.log(this.form);
  },
  methods: {
    async submitForm() {
      const res = await warehouse.editWarehouse(this.editWarehouseID, this.form)
      if (res.code < window.MAX_SUCCESS_CODE) {
        this.$message.success(`${res.message}`)
        this.$emit('editClose')
      }
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    back() {
      this.$emit('editClose')
    },
  },
}
</script>

<style lang="scss" scoped>
.el-divider--horizontal {
  margin: 0;
}

.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;

    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }

  .wrap {
    padding: 20px;
  }

  .submit {
    float: left;
  }
}
.el-row {
  width: 1200px;
}
</style>
